from django.shortcuts import render
from .models import ogImage
from .forms import AddForm

# Create your views here.
# def getimage(request):
#     # 判断是否为 post 方法提交
#     if request.method == "POST":
#         af = AddForm(request.POST, request.FILES)
#         # 判断表单值是否和法
#         if af.is_valid():
#             # name = af.cleaned_data['name']
#             headimg = af.cleaned_data['headimg']
#             user = User( headimg=headimg)
#             user.save()
#
#         return render(request, 'getimage/index.html',context={"user":user})
#
# #
# # def getimage(request):
# #
# #
# return  render(request,'getimage/index.html')



def getimage (request):
    if request.method == "POST":
        form = AddForm(request.POST, request.FILES)
        # 判断表单值是否和法
        if form.is_valid():
            name = form.cleaned_data['name']
            addtime = form.cleaned_data['addtime']
            OgImage = form(name=name, addtime=addtime)
            OgImage.save()
            return render(request, 'getimage/index1.html', context={"OgImage":OgImage})
    else:
        # form = getimage()
        # OgImage =form()

        form = AddForm()
        return render(request, 'getimage/index1.html',context={"form":form})
